package main

import (
	"fmt"
	"time"
)

// time
func main() {
	now := time.Now()
	fmt.Println(now)
	fmt.Println(now.Year())
	fmt.Println(now.Month())
	fmt.Println(now.Date())
	fmt.Println(now.Hour())
	fmt.Println(now.Minute())
	fmt.Println(now.Second())

	// 时间戳
	fmt.Println(now.Unix())
	fmt.Println(now.UnixNano())

	// 时间间隔
	fmt.Println(time.Hour)
	fmt.Println(time.Second)

	// 时间运算
	fmt.Println(now.Add(24 * time.Hour))

	// 定时器
	// timer := time.Tick(time.Second)
	// for t := range timer {
	// 	fmt.Println(t)
	// }

	// 格式化时间
	// 需要使用指定的时间作为模板
	fmt.Println(now.Format("2006-01-02"))

	fmt.Println(time.Parse("2006-01-02", "2020-02-02"))
}
